home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / swtools / MMmalloc / README < prev   
Encoding:
Text File  |  1994-08-02  |  28.0 KB  |  672 lines

  1.  
  2.  
  3. MMmalloc
  4.  
  5. Alpha Release    V.23
  6.  
  7.                         Gianni Mariani 7-Apr-1994
  8.  
  9. Intro
  10. -----
  11.  
  12. This library, pronounced "M" "M" malloc, is a plug in replacement of
  13. the "libmalloc" library ( see malloc(3X) ). In general it is faster,
  14. more memory efficient and has better functionality than the original
  15. libmalloc.  A major feature is to be able to recycle memory so as to
  16. reduce swapping and swap requirements.  Compared to the recent version
  17. of libc's malloc it is faster with comparable memory usage and aging
  18. characteristics.
  19.  
  20. It is important to note that all comments on other libraries or
  21. features in this document will refer to IRIX 5.2 and not to earlier
  22. IRIX releases.
  23.  
  24. Feature Summary
  25. ---------------
  26.  
  27. MMmalloc feature set brief.
  28.  
  29.  . Plug replacement for /lib/libmalloc.so. ( see malloc(3X) )
  30.  . Faster than libmalloc and libc's malloc.
  31.  . More memory efficient than libmalloc.
  32.  . Memory recycle feature.
  33.  . Highly tunable yet easy to use defaults.
  34.  . Tuned realloc performance.
  35.  . Malloc trash debugging support.
  36.  . Better shared memory arena support.
  37.  . Better memalign support.
  38.  . Tunable alignment of addresses returned by malloc.
  39.  
  40. Performace of any malloc library is highly dependent on the pattern of
  41. memory usage by the application.  Relative performance of various
  42. malloc's can vary wildly even on different data sets in the same
  43. application so performance quotes are highly subjective.  However most
  44. malloc's have none or limited ways of tuning while MMmalloc is very
  45. flexible.
  46.  
  47. Where is MMmalloc suited ?
  48. --------------------------
  49.  
  50. MMmalloc suits larger long lived applications with large cyclic memory
  51. usage.  Example are the X Server, image processing applications,
  52. large database servers and larger Motif applications.
  53.  
  54. Where is MMmalloc NOT suited ?
  55. ------------------------------
  56.  
  57. Short lived applications with small dynamic memory usage.  In these
  58. cases you should stick it out with libc since it has excellent malloc
  59. characteristics for this sort of application.
  60.  
  61. Files in this Directory
  62. -----------------------
  63.  
  64. README            : this->README
  65. MMinstall        : csh script to install MMmalloc onto an IRIX 5.2 system
  66. MMfire            : sh script to make all armed processes call recycle
  67. MMdbx            : dbx script to dump information about an MMmalloc error
  68. libmalloc.so        : the MMmalloc libmalloc plug compatible dso
  69. libamalloc.so        : the MMmalloc amalloc library ( see amalloc(3P) )
  70. MMmalloc.h        : additional MMmalloc defines to compliment <malloc.h>
  71.  
  72. How to use MMmalloc
  73. -------------------
  74.  
  75. MMmalloc can be installed as the default libmalloc library for a
  76. system. This will effect all applications linked with libmalloc. To
  77. install MMmalloc you can use MMinstall in the same directory you found
  78. this README file. Simply invoke MMinstall as root and any applications
  79. linked with libmalloc (-lmalloc) will now use MMmalloc.  MMinstall will
  80. place the original libmalloc in /lib/libmalloc.so.orig and the MMmalloc
  81. library will be /lib/libmalloc.so .
  82.  
  83. If you are less inclined to adventure you can also set the environment
  84. variable LD_LIBRARY_PATH to the directory that contains the MMmalloc
  85. library however you will need to create /var/malloc/ArmMMmalloc
  86. yourself if you wish to try MMfire.  See rld(1) for more detail.
  87.  
  88. You may also use MMmalloc with ELF binaries not linked with -lmalloc by
  89. setting the environment variable _RLD_LIST as below.
  90.  
  91.     _RLD_LIST=libmalloc.so:DEFAULT
  92.     export _RLD_LIST
  93.  
  94. A small shell script named MMfire will send a SIGRTMIN signal to all
  95. processes that are currently are armed to recycle().  The contents of
  96. the file /tmp/MMmalloc.log will contains a recycle report if it is
  97. enabled. The signal used may be changed in the future.  Do not create a
  98. production application that depends on MMmalloc using SIGRTMIN for
  99. recycle as it will likely fail in future releases of MMmalloc.  MMfire
  100. will kill some applications that reset the SIGRTMIN signal (e.g. 4Dwm
  101. or Xsgi).
  102.  
  103. MMfire usage :
  104.     MMfire    : fire recycle and echo lines added to /tmp/MMmalloc.log
  105.     MMfire -s    : silent operation
  106.     MMfire -v    : List process armed and fire recycle.
  107.     MMfire -u    : Don't fire recycle but list processes currently armed.
  108.  
  109. MMdbx contains a simple set of dbx commands do print malloc_check
  110. information if it is available.  If values printed are (nil) then
  111. malloc_check did not detect a corruption.  See more information on
  112. malloc_check and MALLOC_DEBUG below.
  113.  
  114. Description
  115. -----------
  116.  
  117. The algorithm used in MMmalloc is similar on the surface to libmalloc.
  118. The libmalloc algorithm uses two types of allocators.  One is a "quick"
  119. allocator for small allocations of equal size and the other a more
  120. traditional free list search allocator.  There are a set of quick
  121. allocators, each dedicated to requests of a single size ( sizes are
  122. rounded up to some power of 2 ) each quick allocator will allocate a
  123. large block which it will use to satisfy multiple smaller requests. 
  124. The normal allocator in libmalloc is a non-exhaustive linear free list
  125. search allocator.  MMmalloc has a similar two staged approach with
  126. totally new allocation and deallocation algorithms.
  127.  
  128. MMmalloc's "quick" allocator is adaptive. Most applications will make
  129. many malloc requests for a small set of sizes. The "quick" allocator
  130. will only be activated after a threshold number of requests for a
  131. particular size have been issued.  This saves memory from avoiding the
  132. allocation of mostly empty large quick allocator blocks for rarely used
  133. sizes.  Another adaptiveness is that the quick block size will grow as
  134. the number of requests for a size increases to minimize the amount of
  135. time allocating and freeing quick allocator blocks.  One major
  136. advantage over libmalloc is that MMmalloc quick allocator blocks are
  137. free'd to the normal allocator once all quick allocations in a quick
  138. block are free'd while libmalloc will always retain a quick allocator
  139. block for a quick allocator of a particular size.  This flexibility
  140. makes MMmalloc quick allocators suited for larger sizes with less waste
  141. than libmalloc. Quick allocators also have a 4 byte header overhead for
  142. each allocation so they may use less memory than the normal allocator
  143. which has an 8 byte overhead. ( 64 bit systems have 8/16 byte overhead)
  144.  
  145. Improvements in the normal allocator come from the manipulation of
  146. multiple free lists.  libmalloc basically has three free lists.  One
  147. list for free blocks too small and hence ignored by malloc but
  148. coalescable by free, one for the most recently sbrk'd block and the
  149. main long double linked list of free blocks. MMmalloc can utilize
  150. hundreds of free lists in a three tiered linear sized bucket
  151. configuration. Indeed the algorithm becomes an exercise in efficient
  152. management of free lists.  For example, the default configuration of
  153. MMmalloc has 130 free lists, the first 120 lists cover sizes of
  154. multiples of 32, the next 7 lists are multiples of 4096 and the last 3
  155. are multiples of 262144 with the last list taking all the rest. Each
  156. free list behaves in a similar fashion to the main libmalloc free list.
  157. An allocation attempt will check a number of the first elements on the
  158. free list but not exhaustive, in this regard it is the same as
  159. libmalloc, however, libmalloc will request a new block from the system
  160. at this point while MMmalloc will grab the first block from the next
  161. largest referenced non-empty free list and partition it as required.
  162. The trick to performance is keeping the free lists consistent is to NOT
  163. keep them optimal all the time.  Free lists reference the next largest
  164. and usually non-empty "pivotal" free lists to avoid searching all the
  165. lists all the time.  The pivot lists are partially rehashed
  166. ( recomputed ) once a number of allocations have been made on a "dirty"
  167. pivot.  This means that the free block found is not always optimal but
  168. "most times highly" optimal.
  169.  
  170. MMmalloc realloc performance for small sizes is optimized since it uses
  171. it's own memcpy routine that assumes double word and non-overlapped
  172. data.  Since it is difficult to extend sizes of quick blocks, MMmalloc
  173. realloc will promote 'quick' allocations to normal allocations based on
  174. some threshold destination size constant.
  175.  
  176. One major difference between most other mallocs and MMmalloc is method
  177. of coalescing blocks being freed.  At free() time, most other mallocs
  178. will coalesce adjacent free'd blocks ( forward as well as backward )
  179. however, MMmalloc will take short cuts and only coalesce free'd blocks
  180. directly after the one being free'd.  This reduces the amount of effort
  181. spent coalescing and partitioning blocks.  Depending on some threshold
  182. conditions, MMmalloc will coalesce selected free blocks when it has
  183. exhausted searches. This helps the multiple free list algorithm so as
  184. to distribute free blocks to the many free lists hence reducing the
  185. time rehashing dirty pivots as well as partitioning large free blocks.
  186.  
  187. As mentioned earlier, MMmalloc allows the application to unmap unused
  188. pages. This is performed by the introduction of the "recycle()" entry
  189. point. Recycle coalesces free blocks and performs garbage collection
  190. and recycling ( return to the operating system ). This creates yet
  191. another level to the allocation hierarchy being the unmapped allocator
  192. which has similar properties to the main MMmalloc allocator but
  193. dedicated to unmapped or `untouchable' pages.  There is also a
  194. re-entrant version of recycle named rerecycle() that is safe to be
  195. called by a signal handler. On return from rerecycle it is not
  196. guaranteed that recycling has actually been performed but that
  197. recycling will be performed if it safe to do so or by the process
  198. currently inside MMmalloc's routines before it returns. rerecycle also
  199. checks to see if it is worthwhile to call recycle by checking the
  200. amount of memory returned by free() since the last time it was called
  201. to avoid an unnecessary walk of the arena.
  202.  
  203. MMmalloc's memalign is persistent.  A block returned by memalign will
  204. retain alignment even after a realloc if it's new size permits it to
  205. be.
  206.  
  207. MMmalloc also has a sibling library to emulate the amalloc(3P)
  208. interface. libamalloc.so uses MMmalloc's libmalloc.so for it's main
  209. allocation routines instead of providing a completely different set.
  210. Also available is the ability to add memory to your arena with the
  211. aaddmem function.  This is useful for extending the size of an arena
  212. when you have unrelated processes sharing an arena rather than using
  213. the "grow" callback function which may not be in the same address space
  214. for every process.
  215.  
  216.  
  217. Additional Features
  218. -------------------
  219.  
  220. MMmalloc is sensitive to the environment variable MALLOC_DEBUG. 
  221. Setting MALLOC_DEBUG to 1 will force MMmalloc to check the arena for
  222. consistentcy on every call to the library.  Setting this to 1 makes
  223. calls the MMmalloc very slow since the entire arena is checked for
  224. consistentcy on every call.  This is the same as calling
  225. mallopt(M_DEBUG,1).  Successfull return when debug mode is on will
  226. guarantee that the malloc data structures are consistent. 
  227. malloc_check() can also be called at any time by the application to
  228. validate arena consistentcy.
  229.  
  230. This version of MMmalloc also has a built in signal handler attached to
  231. SIGRTMIN that is armed if the file /var/malloc/ArmMMmalloc exists and
  232. is readable and the environment variable MALLOC_NOARM is not set. The
  233. file /var/malloc/ArmMMmalloc is kept open so that it can easily be
  234. identified which processes are currently armed by fuser(1M). This is
  235. intended for use by an external swap monitor daemon that will send
  236. SIGRTMIN signals to the armed processes. On receipt of a SIGRTMIN, the
  237. application will be forced to call recycle and a report of memory
  238. recycled will be placed in /tmp/MMmalloc.log if enabled. The logging is
  239. enabled by default but can be disabled by the second character in the
  240. MALLOC_DEBUG variable. To disable malloc debugging and recycle logs use
  241. MALLOC_DEBUG="00". To enable recycle logs only use MALLOC_DEBUG="01".
  242. To enable both use MALLOC_DEBUG="11".
  243.  
  244. The MALLOC_CONFIG environment variable allows the selection of a
  245. configuration of constants that MMmalloc utilizes in it's algorithms.
  246. MALLOC_CONFIG can be set between 1 and 4 with the following meanings.
  247.  
  248.     1 - default - fast and memory efficient
  249.     2 - faster and memory hog
  250.     3 - slower and more memory efficient
  251.     4 - tuned for libil and fast big memory hog with good aging
  252.  
  253. The MALLOC_CONFIG default can be set by the application by setting a
  254. global variable int _mm_defaultoptions = N; Where N is 1-4 as above.
  255.  
  256. MALLOC_CONFIG can also be used to tweak the configuration being used.
  257. The intention is to allow the programmer to tweak the configuration
  258. during an applications optimization.  It is not intended as an ugly
  259. interface to the malloc library and should not be used in production
  260. code as it will likely change in the future.  The string in
  261. MALLOC_CONFIG can be a colon ( : ) separated list of configuration
  262. parameters.  The parameter name is followed by an equal ( = ) and a
  263. numeric string that will be used as it's parameter. No white space is
  264. tolerated. The parameters are not totally independent and bad values
  265. will cause MMmalloc to fail.
  266.  
  267. The following example will set the mm_ntopromo parameter to 300 and
  268. mm_minslots to 256 and use the default values from config 1. Numbers
  269. with a leading '0' are assumed to be base 8 and '0x' are base 16.
  270.  
  271.     MALLOC_CONFIG="1:mm_ntopromo=300:mm_minslots=0x100"
  272.     export MALLOC_CONFIG
  273.     <run application>
  274.  
  275. Care should be taken when choosing new configuration values as they are
  276. interdependent. The following are the MALLOC_CONFIG parameters. Values
  277. in ()'s are the settings for the default configurations 1-4
  278. respectively.
  279.  
  280. mm_asizshft    (3 3 3 4)
  281.  
  282.     This is the size requested granularity adjustment parameter. 
  283.     All malloc requests will be rounded upwards to the nearest
  284.     multiple of 2^mm_asizshft. It is bad to have mm_asizshft less
  285.     than 3.  e.g. mm_asizshft=4 will round all requests to the
  286.     nearest multiple of 16. If mm_nszmult=16 it will guarantee that
  287.     all allocations will be returned on a 16 byte boundary.  Quick
  288.     allocator slots will also be based on multiples of this size.
  289.     mm_asizshft should not be set to less than 2 on 32 bit systems
  290.     and 3 on 64 bit systems.
  291.     
  292.     mm_asizshft also determines the alignment of pointers returned
  293.     by malloc and realloc.
  294.  
  295.  
  296. mm_ntopromo    (20 10 0 0)
  297.  
  298.     This is the number of requests required for a quick allocator
  299.     before actually activating the quick allocator for that size.
  300.  
  301. mm_nqalist    (5 34 7 128)
  302.  
  303.     This is the number of quick allocators that will be used.  This
  304.     determines the size of the largest request that can be destined
  305.     for the quick allocators.
  306.  
  307.     max quick allocator size =
  308.         mm_nqalist * ( 1 << mm_asizshft ) - overhead
  309.  
  310.     overhead in this case is the size of a pointer which is 4 bytes
  311.     on a 32 bit system and 8 bytes on a 64 bit system.
  312.  
  313. mm_maxslots    (120 120 30 45)
  314.  
  315.     Quick allocator block sizes grow as a proportion of the number
  316.     of requests for a quick allocator.  This will be pegged to
  317.     mm_maxslots to avoid creating quick allocator blocks that are
  318.     too large.  The larger the block the less likely it all quick
  319.     allocations in it will be free'd and hence it becomes locked
  320.     into a quick allocator instead of potentially returning it to
  321.     the main pool.
  322.  
  323. mm_minslots    (10 5 20 2)
  324.  
  325.     This is the minimum number of slots allowed for a quick
  326.     allocator block.  If there are too few allocations then the
  327.     computed number of slots may be too small so this will limit
  328.     the minimum value.
  329.  
  330. mm_adjfactor    (12 16 24 6)
  331.  
  332.     This if the quick block size adjustment factor.  This is used
  333.     to scale the number of `extensions' for a slot to the number to
  334.     allocate for a new extension.  Extension is allocation of a new
  335.     large block.  mm_adjfactor is normalized at 16.  An
  336.     mm_adjfactor value of 16 is a scale of 1.0.  e.g. setting the
  337.     mm_adjfactor to 8 ( making it a scale of 0.5 ) will evaluate
  338.     the number of slots in a new extension to be 0.5 * the number
  339.     of slots extended so far for a quick allocator.
  340.  
  341. mm_qblkmult    (64 256 8 4096)
  342.  
  343.     On top of all the minimum and maximum settings, the size of the
  344.     quick allocator blocks are rounded up to the nearest multiple
  345.     of mm_qblkmult.  mm_qblkmult must be a power of 2 otherwise
  346.     MMmalloc will fail.
  347.  
  348. mm_nszmult    (8 16 8 2048)
  349.  
  350.     This is the granularity adjustment for the normal allocator. 
  351.     All allocations in the normal allocator will be rounded to this
  352.     value. This must be a power of 2.  Setting this value to less
  353.     than 4 will cause MMmalloc to fail.
  354.  
  355. mm_xf[0].mm_flindx  (120  90 110  63)
  356. mm_xf[0].mm_szshft  (  5   5   4  11)
  357.  
  358. mm_xf[1].mm_flindx  (127 105 125  94)
  359. mm_xf[1].mm_szshft  ( 12  12  11  17)
  360.  
  361. mm_xf[2].mm_flindx  (129 109 129 110) 
  362. mm_xf[2].mm_szshft  ( 18  16  17  22)
  363.  
  364.     The above values determine the free list number selection. 
  365.     These are used to determine what free list index to search for
  366.     an allocation request of a given size. There are three pairs of
  367.     mm_flindx and mm_szshft parameters.  Each set determines an
  368.     allocation tier.  The size requested is shifted by mm_szshft
  369.     bits to the right ( division by 2^mm_szshft ) and the resultant
  370.     value is compared to mm_flindx to determine if the size belongs
  371.     on the next tier or the value is adequate for an index.  On the
  372.     last tier, sizes that are beyond are dropped into the last free
  373.     list.  It is important that the following relation is held true
  374.     otherwise unpredictable results will occur :
  375.  
  376.     mm_xf[N].mm_flindx*(1 << mm_xf[N].mm_szshft) < (1 << mm_xf[N+1].mm_szshft)
  377.  
  378.     Setting parameters such that (mm_xf[0].mm_flindx << 1) is less
  379.     than mm_nszmult will cause unused free lists to be created which
  380.     is a waste.
  381.  
  382. mm_zeromalloc    (0 0 0 0)
  383.  
  384.     This determines the behavior of malloc( 0 ).  mm_zeromalloc=0
  385.     will force malloc to return ( void * ) 0.  mm_zeromalloc=1 will
  386.     force malloc to return a pointer that can be used to call
  387.     free(). Any dereferences to the pointer will have undefined
  388.     behavior.
  389.  
  390. mm_maxsrch    (20 50 20 512)
  391.  
  392.     This determines the number of attempts to search a free list
  393.     before giving up and using a larger free list.  Larger values
  394.     will persist in searching a free list and hence trade off speed
  395.     with memory.
  396.  
  397. mm_brkmult    (8192 16384 16384 16384)
  398.  
  399.     When memory is requested from the system it will be requested
  400.     in multiples of this size.  It is important that this value be
  401.     a power of 2.
  402.  
  403. mm_minrmdr    (32 32 16 16)
  404.  
  405.     This determines how free blocks are partitioned the smallest.
  406.     If the remaining size in a free block is less than this size
  407.     after partitioning it is not partitioned and memory is assumed
  408.     allocated to the requested block.  It is important that this
  409.     value is not smaller than the size of 4 pointers. 16 bytes on
  410.     a 32 bit system and 32 bytes on a 64 bit system.  It can also
  411.     be used to reduce micro-fragmentation of the arena.
  412.  
  413. mm_gcthresh    (81920 1048576 0 1048576)
  414.  
  415.     After an unsuccessful search of a free list, this value is used
  416.     to determine is a coalesce operation should be performed on the
  417.     free list just searhed.  If more than mm_gcthresh bytes have
  418.     been freed since the last time a coalesce was performed and
  419.     more than mm_gcthresh are  are currently unused in the arena
  420.     then a coalesce will take place.
  421.  
  422. mm_missthrash    (6 10 4 2)
  423.  
  424.     This determines the number of allocations on a dirty pivot that
  425.     will be satisfied before a rehash of the free list is computed.
  426.  
  427. mm_flsearh    (20 10 60 10)
  428.  
  429.     This determines the number of empty pivot free lists that will
  430.     be tolerated before a rehash of the free lists.
  431.  
  432. mm_reallthrsh    (128 128 64 256)
  433.  
  434.     This is used by realloc to determine what sizes will be
  435.     reallocated in the normal arena instead of the quick arena.
  436.  
  437. mm_nunmaplists    (16 8 8 8 )
  438.  
  439.     This determines the number of unmapped free lists used. These
  440.     will be used by recycle to keep unmapped regions from the main
  441.     arena but will allocate from these regions before calling
  442.     sbrk() again.
  443.  
  444. mm_szunmapshift    (14 12 12 12)
  445.  
  446.     This determines the sizes of the unmapped lists. This will be
  447.     used in a similar way to mm_xf[0].mm_szshft but there is only
  448.     one tier.
  449.  
  450. mm_unmapalign    (4096 4096 4096 4096)
  451.  
  452.     This must be equal to the pagesize of the system.  This will be
  453.     used to determine which boundaries are suitable to mmap/munmap.
  454.  
  455. mm_minunmapsize    (8192 4096 4096 4096)
  456.  
  457.     This determines the smallest region that will be unmapped.
  458.  
  459. mm_minunmapsrch    (0 0 0 0)
  460.  
  461.     This determines the smallest free list size that will be used
  462.     for coalescing by recycle.
  463.  
  464. mm_minfreerecy    (0 0 0 0)
  465.  
  466.     This is used by rerecycle to determine how many bytes must be
  467.     available before it will call recycle.
  468.  
  469. mm_debug_on    (0 0 0 0)
  470.  
  471.     mm_debug_on sets debug mode on if it is 1 and off if 0. Setting
  472.     this to 1 is the same as setting MALLOC_DEBUG to 1.  This will
  473.     force a malloc_check to be performed on every entry to MMmalloc.
  474.  
  475. mm_abort_badfree (0 0 0 0)
  476.  
  477.     This determines behavior of a free of an already free'd block.
  478.     Setting mm_abort_badfree to 1 will cause MMmalloc to core dump
  479.     on a free of an unidentifiable block.  Setting this value to 2
  480.     will force mmalloc print messages regarding the error on
  481.     standard error (stderr).
  482.  
  483. mm_clronfree    (0 0 0 0)
  484. mm_valclronfree    (0 0 0 0)
  485.  
  486.     mm_clronfree can be set to 1 which will enable the clear on free
  487.     option as in mallopt.  mm_valclronfree will be used as the value
  488.     to use.
  489.  
  490. mm_reportrecy    (0 0 0 0)
  491.  
  492.     Setting mm_reportrecy to 1 will disable rerecycle reporting to
  493.     the /tmp/MMmalloc.log file.
  494.  
  495. The MM_CONFIG structure can also be used to determine compile time
  496. parameters for the malloc configuration.
  497.  
  498. New Functions in MMmalloc
  499. -------------------------
  500.  
  501. size_t    recycle( void )
  502. size_t  arecycle( void * arena )
  503.  
  504.     This will coalesce all free lists with sizes larger than a threshold
  505.     (mm_minunmapsrch) and unmap pages that are completely free and larger
  506.     than a threshold (mm_minunmapsize).
  507.  
  508.     Recycle will call _mm_munmap and _mm_mmapmem to map and unmap memory
  509.     in the arena.  These are provided as weak symbols and can be
  510.     overridden by the application to perform a similar but perhaps
  511.     different operation.  The same functions will be called by arecycle.
  512.  
  513. void rerecycle( void )
  514.  
  515.     This is a signal handler safe version of recycle.  It is not guaranteed
  516.     that recycle will have been called on return from rerecycle but it will
  517.     be called either by the signal handler or the process that currently
  518.     has the malloc lock before it returns from the malloc library call.
  519.     There is no arerecycle() entry point.
  520.  
  521.     rerecycle() will also write a summary line in /tmp/MMmalloc.log if
  522.     it mm_reportrecy is set to 0 and mm_minfreerecy bytes have been
  523.     free'd since the last call to recycle().
  524.  
  525.     The following is an example of output from PID 27888, the process was
  526.     able to recycle/unmap 139264 bytes from the address space.  It total,
  527.     196608 bytes have been allocated by sbrk and 49240 bytes are still
  528.     allocated to the application. Memory left is either free or overhead
  529.     in MMmalloc.
  530.     
  531.  27888 - recycled    139264 sbrk    196608 unmapped    139264 aloc     49240
  532.  
  533.  
  534. void malloc_check( void )
  535. void amalloc_check( void * arena )
  536.  
  537.     This will validate the malloc arena data structures to make sure there
  538.     is no corruption.  On failure, malloc_check will NOT return to the
  539.     caller but will force a SIGSEGV signal.  If malloc_check was able to
  540.     identify a problem it will write an error message to standard error
  541.     ( file descriptor 2 - not stderr ).
  542.     
  543.     Bad quick slot : overwrite before allocated mem
  544.     **** MMmalloc panic identifier 0x10000a16
  545.     **** Possible problem/corrupted addresses 0x10056744 or 0x10053b20
  546.     Dumping core
  547.     Process 25934 (mstress.mm)  Segmentation fault (Signal 11)
  548.  
  549.     The message will usually have a likely cause of error after a ':'.
  550.     It is impossible to determine exactly what the problems are so
  551.     take this likely cause of error as a guess only.
  552.     
  553.     The following is output using the MMdbx dbx script. This is output 
  554.     from MMdbx on the error corresponding to the failure above.
  555.     
  556.     0x5fff0934 = "Bad quick slot : overwrite before allocated mem\n"
  557.     0x100572e4
  558.     0x10056b88
  559.     0x10000a16
  560.     2
  561.     1
  562.  
  563.     There will be two likely problem addresses printed that could be the
  564.     corrupted words.  The most likely problem address is the first one
  565.     printed.  In some cases the second address is the address being
  566.     referenced.  The rest are ID's so that the problem can be traced to
  567.     a line and state in MMmalloc.
  568.  
  569.     malloc_check is very exhaustive but does not detect an invalid virtual
  570.     address before accessing it in all cases.  For some errors,
  571.     malloc_check will be forced to reference an invalid address and it will
  572.     not output any error messages before dumping core.  However you may
  573.     still be able to run the MMdbx script from dbx on the resultant core
  574.     and get meaningfull diagnostics as described above.
  575.  
  576.     It is possible to call malloc_check from the debugger but is only
  577.     reliable if the application is not currently within libmalloc.
  578.     malloc_check also marks and unmarks structures in the arena so it
  579.     is unwise to capture the malloc_check SIGSEGV signal and continue
  580.     operation since all marks may have not been unmarked.
  581.  
  582. struct mallinfo qmallinfo( void )
  583. struct mallinfo aqmallinfo( void * arena )
  584.  
  585.     This is a quick version of mallinfo() that will only fill the following
  586.     fields of the struct mallinfo record :-
  587.     
  588.     arena
  589.     usmblks
  590.     uordblks
  591.     fordblks
  592.     
  593.     These are provided by running totals accumulated by MMmalloc and do
  594.     not require walking the entire arena to compute.
  595.  
  596. void * malignoff( size_t alignment, size_t offset, size_t size )
  597. void * amalignoff( size_t alignment, size_t offset, size_t size, void * arena )
  598.  
  599.     This is a more general version of memalign.  It allows you to provide
  600.     an offset into the allocated memory that is where the alignment is
  601.     desired.  Values for alignment must be a power of 2. malignoff
  602.     does have a larger memory use overhead than malloc so it should
  603.     only be used sparingly.
  604.  
  605. void addmem( void * p_mem, size_t size )
  606. void aaddmem( void * p_mem, size_t size, void * arena )
  607.  
  608.     This allows the application to add any memory to an arena.
  609.  
  610. int _mm_defaultoptions = N;
  611.  
  612.     This allows the application to override the default configuration
  613.     being by having _mm_defaultoptions set before any call to malloc.
  614.  
  615. New mallopt Commands
  616. --------------------
  617.  
  618.     M_ASSIGNLOCK    This is only available to amallopt.  It allows the
  619.             assignment of a lock to an arena.  This is the same
  620.             lock as created by acreate() but it can be assigned
  621.             to the arena at any time.  This only effects the
  622.             amalloc, afree, arealloc, acalloc, amallopt, arecycle,
  623.             amallinfo interface.  For controlling threading on
  624.             malloc, free, realloc, calloc, mallopt, mallinfo,
  625.             recycle, qmallinfo, malloc_check etc you should
  626.             investigate the usconfig function with the parameters
  627.             CONF_STHREADMALLOCOFF or CONF_STHREADMALLOCON.  It
  628.             is also up to the user to free the lock when nessasary.
  629.  
  630.     M_USERDATA        This allows the user to set a data field in the
  631.             arena structure.  This value is later passed to
  632.             _mm_munmap and _mm_mmapmem during a call to recycle.
  633.  
  634. Reporting New Problems
  635. ----------------------
  636.  
  637. In the meantime, you may contact me directly via email if you discover
  638. any problems with MMmalloc.
  639.  
  640.     "Gianni Mariani" <gianni@neu.sgi.com>
  641.  
  642.  
  643. Known Problems or Bugs
  644. ----------------------
  645.  
  646. recycle() will create a large number of virtual memory regions.
  647. IRIX 5.2 has an O(N) algorithm for handling page faults with
  648. respect to the number of mapped regions so the performance will
  649. degrade as more and mapped regions are created.  This is a
  650. problem for any application making extensive use of mmap and
  651. munmap and creating large numbers of regions.  This problem may
  652. be corrected in future releases of IRIX.
  653.  
  654. addmem() touches the last page of memory being added making it
  655. unsuitable for large AUTOGROW mapped files.
  656.  
  657. libmalloc's memalign() behaves sensibly if an alignment other
  658. than a power of two is given while MMmalloc will fail as will
  659. libc's malloc.
  660.  
  661. Do not install MMmalloc on IRIX system release befores 5.2 as you
  662. may expose some nasty bugs in the memory system.
  663.  
  664. malloc_check does not always write an error to standard error.
  665.  
  666. Small shared arenas do not have a reasonable MMmalloc configuration.
  667.  
  668. API for configuring MMmalloc parameters is very weak.
  669.  
  670. .3f04
  671.  
  672.